package com.leo.ktvplayer.ui.login;

import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.provider.Settings;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.leo.ktvplayer.R;
import com.leo.ktvplayer.base.ActBase;
import com.leo.ktvplayer.domain.req.ReqLogin;
import com.leo.ktvplayer.domain.resp.RespLogin;
import com.leo.ktvplayer.localcookie.LocalUtils;
import com.leo.ktvplayer.network.http.HTTPTAG;
import com.leo.ktvplayer.pay.alipay.Alipayment;
import com.leo.ktvplayer.pay.wechat.WechatPayment;
import com.leo.ktvplayer.service.KtvplayService;
import com.leo.ktvplayer.ui.chosetype.ActChoseType;
import com.leo.ktvplayer.ui.setting.ManagerDialog;
import com.leo.ktvplayer.util.JsonUtil;
import com.leo.ktvplayer.util.Md5Util;
import com.leo.ktvplayer.util.QRCodeUtil;
import com.leo.ktvplayer.util.RandomStrUtils;
import com.leo.ktvplayer.util.ToastUtil;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class ActLogin extends ActBase implements View.OnKeyListener {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        ButterKnife.bind(this);
        openBle();//打开蓝牙
        tv_titleText.setOnKeyListener(this);
        startService(new Intent(this, KtvplayService.class));

    }


    @OnClick(R.id.btn_activity_setting)
    public void setting(View view ){

    }
    @OnClick(R.id.btn_activity_login_setup)
    public void setup(View view) {
        Intent intent = new Intent(this,ActChoseType.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(intent);
    }

    @Override
    public boolean onKey(View v, int keyCode, KeyEvent event) {
        if (event.getAction() == KeyEvent.ACTION_DOWN) {
            keyTime = System.currentTimeMillis();
        } else if (event.getAction() == KeyEvent.ACTION_UP) {
            if (System.currentTimeMillis() - keyTime > 1000 * 10){
                ManagerDialog managerDialog = new ManagerDialog(this,R.style.dialog);
                managerDialog.setOnManagerDialogClickedListener((action,text) ->{
                    if (action == ManagerDialog.OnManagerDialogClickedListener.ACTION_POSITIVE){
                        if (TextUtils.isEmpty(text)){
                            ToastUtil.show("密码不能为空");
                        } else if (text .equals(LocalUtils.getUser().getUserpwd())){
                            goSetting();
                            managerDialog.dismiss();
                        }
                    }
                });
                managerDialog.show();
            }
        }
        return false;
    }

    @BindView(R.id.tv_activity_login_title)
    public TextView tv_titleText;

    public long keyTime;
}